package com.yc.vote.service.impl;

import com.yc.common.biz.BizException;
import com.yc.vote.entity.User;
import com.yc.vote.mapper.UserMapper;
import com.yc.vote.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.vote.util.MyBatisHelper;
import com.yc.vote.util.Utils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ly
 * @since 2022-07-03
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    public User login(String uname, String pwd) throws BizException {
        Utils.checkEmpty(uname,"请填写用户名!");
        Utils.checkEmpty(pwd,"请填写密码!");
        User user = MyBatisHelper.query(session -> {
            return session.getMapper(UserMapper.class).selectByLogin(uname,pwd);
        });
        Utils.check(user == null, "用户名或密码错误!");
        return user;
    }

}
